package org.example.rental.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.rental.common.User;
import org.example.rental.domain.SysUser;
import org.example.rental.domain.vo.UserVo;
import org.example.rental.service.SysUserService;
import org.example.rental.mapper.SysUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
* @author xulongxing
* @description 针对表【sys_user(用户表)】的数据库操作Service实现
* @createDate 2023-12-07 00:42:56
*/
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
    implements SysUserService{



    @Autowired
    User user;



    public void saveUserInfo(UserVo userVo) {
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(userVo,sysUser);

        if (userVo.getOldPassword()!=null || userVo.getNewPassword()!=null){
            SysUser currentUser = user.getSysUser();
            sysUser.setId(currentUser.getId());
            if (!userVo.getOldPassword().equals(currentUser.getPassword())){
                throw new RuntimeException("旧密码有误,更新失败");
            }
            sysUser.setPassword(userVo.getNewPassword());

        }

        this.updateById(sysUser);
        user.setSysUser(sysUser);

    }
}




